/**
 * 版权所有:版权所有(C) 2020，卓信科技
 * 系统名称:FOL
 * 文件名称:FolRequestForMobileServiceImpl
 * 模块名称:FolRequestForMobileServiceImpl
 * 创建日期:2020年10月9日 上午9:49:36
 * 作        者:wangyihan
 * 内容摘要:FolRequestForMobileServiceImpl
 */
package com.zx.emanage.postLoanManage.service.impl;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.google.gson.Gson;
import com.zx.emanage.FOLApplication;
import com.zx.emanage.postLoanManage.persist.FolApplyBillRelationDao;
import com.zx.emanage.postLoanManage.persist.FolFinaBillDao;
import com.zx.emanage.postLoanManage.persist.FolFinaBillSubsidiaryDao;
import com.zx.emanage.postLoanManage.persist.FolFinaCollectionPayConfirmDao;
import com.zx.emanage.postLoanManage.persist.FolFinaLoanRelatedBillDao;
import com.zx.emanage.postLoanManage.service.IFolFinaBillService;
import com.zx.emanage.postLoanManage.service.IFolRequestForMobileService;
import com.zx.emanage.postLoanManage.service.SendWechatEmailMsgService;
import com.zx.emanage.postLoanManage.vo.FolFinaBillSearchBeanVO;
import com.zx.emanage.postLoanManage.vo.FolFinaCollectionPayConfirmSearchBeanVO;
import com.zx.emanage.postLoanManage.vo.FolRequestForMobileSearchBeanVO;
import com.zx.emanage.sysmanage.persist.FolFileInfoDao;
import com.zx.emanage.user.persist.PmPersonnelDao;
import com.zx.emanage.user.vo.PmPersonnel;
import com.zx.emanage.util.gen.CodeNoUtil;
import com.zx.emanage.util.gen.FOLMsgInfo;
import com.zx.emanage.util.gen.GlobalVal;
import com.zx.emanage.util.gen.ResultHelper;
import com.zx.emanage.util.gen.entity.FolApplyBillRelation;
import com.zx.emanage.util.gen.entity.FolCreApprovalInfo;
import com.zx.emanage.util.gen.entity.FolFileInfo;
import com.zx.emanage.util.gen.entity.FolFinaBill;
import com.zx.emanage.util.gen.entity.FolFinaBillSubsidiary;
import com.zx.emanage.util.gen.entity.FolFinaLoanRelatedBill;

/**
 * 类  名  称:FolRequestForMobileServiceImpl
 * 内容摘要:接口
 * 作        者:wangyihan
 */
@Service("folRequestForMobileService")
public class FolRequestForMobileServiceImpl implements IFolRequestForMobileService
{
	
	/**
     * @Title: initLoanInfo
     * @Description: MOA_OUT_001  借款单初始化
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    public Map<String, Object> initLoanInfo(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
    		FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		FolFinaBillSubsidiaryDao folFinaBillSubsidiaryDao = (FolFinaBillSubsidiaryDao) FOLApplication.getBean("folFinaBillSubsidiaryDao");
    		PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
    		FolFinaLoanRelatedBillDao folFinaLoanRelatedBillDao = (FolFinaLoanRelatedBillDao) FOLApplication.getBean("folFinaLoanRelatedBillDao");
    		FolFinaCollectionPayConfirmDao folFinaCollectionPayConfirmDao = (FolFinaCollectionPayConfirmDao) FOLApplication.getBean("folFinaCollectionPayConfirmDao");
    		FolFileInfoDao folFileInfoDao = (FolFileInfoDao) FOLApplication.getBean("folFileInfoDao");
    		
    		Map<String, Object> ret_data = new HashMap<String, Object>();
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
    		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    		Date now_date = new Date();
    		List<Map<String, Object>> pictureList = new ArrayList<Map<String, Object>>();
    		Gson gson = new Gson();
    		//银行卡信息
    		List<Map<String, Object>> collection_information_list=new ArrayList<>();

			PmPersonnel pmPersonnel = pmPersonnelDao.findPersonnelById(paramMap.get("user_id").toString());
			// 是否存在签名
			ret_data.put("is_sign", pmPersonnel.getIs_sign());
    		// 判断
    		if(paramMap.get("fol_fina_bill_id") != null)
    		{
    			Integer fol_fina_bill_id = Integer.parseInt(paramMap.get("fol_fina_bill_id").toString());
    			Integer fol_fina_bill_subsidiary_id = Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id").toString());
    			FolFinaBill folFinaBill = folFinaBillDao.get(fol_fina_bill_id);
    			FolFinaBillSubsidiary folFinaBillSubsidiary = folFinaBillSubsidiaryDao.get(fol_fina_bill_subsidiary_id);
    			
    			ret_data.put("apply_date", format.format(folFinaBill.getApply_date()));
    			ret_data.put("apply_user_name", folFinaBill.getApply_user_name() + " " + folFinaBill.getApply_user_shrotcode());
    			ret_data.put("apply_user_postname", folFinaBill.getApply_user_postname());
    			ret_data.put("apply_user_deptname", folFinaBill.getApply_user_deptname());
    			ret_data.put("apply_user_pdeptname", folFinaBill.getApply_user_pdeptname());
    			ret_data.put("bill_type", folFinaBillSubsidiary.getLoan_type());
				ret_data.put("bill_type_name", folFinaBillSubsidiary.getLoan_type() != null ? "电汇" : "");
    			ret_data.put("bill_cause", folFinaBillSubsidiary.getBill_cause() != null ? folFinaBillSubsidiary.getBill_cause() : "");
    			ret_data.put("loan_amount", folFinaBillSubsidiary.getTotal_amount() != null ? folFinaBillSubsidiary.getTotal_amount().stripTrailingZeros().toPlainString() : null);
				ret_data.put("card_default", folFinaBillSubsidiary.getCard_default());

    		/*	ret_data.put("receivables_name", folFinaBillSubsidiary.getReceivables_name());
    			ret_data.put("receivables_bank", folFinaBillSubsidiary.getReceivables_bank());
    			ret_data.put("receivables_bank_branch", folFinaBillSubsidiary.getReceivables_bank_branch());
    			ret_data.put("receivables_bank_number", addSpaceForCardNo(folFinaBillSubsidiary.getReceivables_bank_number()));
    			
				ret_data.put("card_default", folFinaBillSubsidiary.getCard_default());
				ret_data.put("receivables_bank_branch", folFinaBillSubsidiary.getReceivables_bank_pro());
				ret_data.put("receivables_bank_city", folFinaBillSubsidiary.getReceivables_bank_city());
				ret_data.put("receivables_bank_branch", folFinaBillSubsidiary.getReceivables_bank_pro_str());
				ret_data.put("receivables_bank_city", folFinaBillSubsidiary.getReceivables_bank_city_str());*/

				Map<String, Object> cardMapOther=new HashMap<>();
				cardMapOther.put("receivables_name", folFinaBillSubsidiary.getReceivables_name());
				cardMapOther.put("receivables_bank", folFinaBillSubsidiary.getReceivables_bank());
				cardMapOther.put("receivables_bank_branch", folFinaBillSubsidiary.getReceivables_bank_branch());
				cardMapOther.put("receivables_bank_number", addSpaceForCardNo(folFinaBillSubsidiary.getReceivables_bank_number()));
				cardMapOther.put("receivables_bank_pro", folFinaBillSubsidiary.getReceivables_bank_pro());
				cardMapOther.put("receivables_bank_city", folFinaBillSubsidiary.getReceivables_bank_city());
				cardMapOther.put("receivables_bank_pro_name", folFinaBillSubsidiary.getReceivables_bank_pro_str());
				cardMapOther.put("receivables_bank_city_name", folFinaBillSubsidiary.getReceivables_bank_city_str());
				cardMapOther.put("bank_num", folFinaBillSubsidiary.getBank_num());
				
				collection_information_list.add(cardMapOther);

                paramMap.put("enable_flag", "1");
                paramMap.put("sortname", "fol_fina_loan_related_bill_id");
                paramMap.put("sortorder", "asc");
                List<Map<String, Object>> related_bill_list = folFinaLoanRelatedBillDao.search(paramMap);
                // 判断
                if (related_bill_list != null && related_bill_list.size() > 0)
                {
                	Map<String, Object> related_bill = related_bill_list.get(0);
                	ret_data.put("related_bill_id", related_bill.get("related_bill_id"));
                	ret_data.put("related_bill_code", related_bill.get("related_bill_code"));
                	ret_data.put("related_bill_type", related_bill.get("related_bill_tpye"));
                	ret_data.put("goods_price", related_bill.get("goods_price"));
                	ret_data.put("related_bill_detail", related_bill.get("related_bill_detail"));
                	
                	// 查询物品申请单附件
                	Map<String, Object> paramMap_file = new HashMap<String, Object>();
                	paramMap_file.put("fol_other_id", related_bill.get("fol_fina_loan_related_bill_id"));
                	paramMap_file.put("attachment_module", FOLMsgInfo.FILE_CODE_WPSQD);
                	List<Map<String, Object>> file_list = folFileInfoDao.search(paramMap_file);
                	// 判断
                	if(file_list != null && file_list.size() > 0)
                	{
                		ret_data.put("img_path", gson.toJson(file_list));
                	}
                	else
                	{
                		ret_data.put("img_path", "");
                	}
                }
                else
                {
                	ret_data.put("related_bill_id", "");
                	ret_data.put("related_bill_code", "");
                	ret_data.put("related_bill_type", "");
                	ret_data.put("goods_price", ""); 
                	ret_data.put("related_bill_detail", "");
                }
                
                paramMap.put("sortname", null);
                paramMap.put("sortorder", null);
                paramMap.put("confirm_type_ne", "5");
                List<Map<String, Object>> sxkList = folFinaCollectionPayConfirmDao.search(paramMap);
                // 判断
                if(paramMap.get("Initial_sort_id").toString().equals("5"))
                {
                	// 判断
                	if (sxkList != null && sxkList.size() > 0)
                	{
                		ret_data.put("confirm_amount", new BigDecimal(sxkList.get(0).get("confirm_amount").toString()).stripTrailingZeros().toPlainString());
                	}
                	else
                	{
                		ret_data.put("confirm_amount", folFinaBillSubsidiary.getTotal_amount().stripTrailingZeros().toPlainString());
                	}
                }
                // 判断
                else if(paramMap.get("Initial_sort_id").toString().equals("6"))
                {
                	// 判断
                	if (sxkList != null && sxkList.size() > 0)
                	{
                		ret_data.put("confirm_date", sxkList.get(0).get("confirm_date"));
                		ret_data.put("confirm_amount", new BigDecimal(sxkList.get(0).get("confirm_amount").toString()).stripTrailingZeros().toPlainString());
                	}
                	else
                	{
                		ret_data.put("confirm_date", format.format(now_date));
                		ret_data.put("confirm_amount", folFinaBillSubsidiary.getTotal_amount().stripTrailingZeros().toPlainString());
                	}
                }
                else
                {
                	ret_data.put("confirm_date", "");
            		ret_data.put("confirm_amount", "");
                }
                
                // 判断
            	if (sxkList != null && sxkList.size() > 0)
            	{
            		paramMap.put("fol_id", paramMap.get("fol_fina_bill_id"));
            		paramMap.put("fol_other_id", sxkList.get(0).get("fol_fina_collection_pay_confirm_id"));
            		List<Map<String, Object>> pictureAllList = folFileInfoDao.search(paramMap);
            		Map<String, Object> map = new HashMap<String, Object>();
            		// 循环
            		for(Map<String, Object> tmpMap : pictureAllList)
            		{
            			map.put("pic_address", tmpMap.get("attachment_address").toString());
            			pictureList.add(map);
            		}
            	}
            	
        		ret_data.put("pictureList", pictureList);
        		
        		paramMap.put("attachment_module", FOLMsgInfo.FILE_CODE_DJSQ);
				paramMap.put("fol_id", paramMap.get("fol_fina_bill_id"));
				List<Map<String, Object>> img_List = folFileInfoDao.searchMobileInfo(paramMap);
                // 判断
                if(img_List != null)
                {
					ret_data.put("img_List", img_List);
                }
                else
                {
					ret_data.put("img_List", new ArrayList<Map<String, Object>>());
                }	
    		}
    		else
    		{


    			ret_data.put("apply_date", format.format(now_date));
    			ret_data.put("apply_user_name", pmPersonnel.getPersonnel_name() + " " + pmPersonnel.getPersonnel_shortCode());
    			ret_data.put("apply_user_postname", pmPersonnel.getPersonnel_postName());
    			ret_data.put("apply_user_deptname", pmPersonnel.getPersonnel_deptName());
    			ret_data.put("apply_user_pdeptname", pmPersonnel.getDept_pname());
				ret_data.put("bill_type", "");
				ret_data.put("bill_type_name", "");
    			ret_data.put("bill_cause", "");
    			ret_data.put("loan_amount", "");
    			/*ret_data.put("receivables_name", pmPersonnel.getPersonnel_name());
    			ret_data.put("receivables_bank", pmPersonnel.getPersonnel_bank_title());
    			ret_data.put("receivables_bank_branch", pmPersonnel.getPersonnel_bankName());
    			ret_data.put("receivables_bank_number", addSpaceForCardNo(pmPersonnel.getPersonnel_bankCardCode()));
    			*/
    			Map<String, Object> cardMap = new HashMap<>();
				cardMap.put("receivables_name", pmPersonnel.getPersonnel_name());
				cardMap.put("receivables_bank", pmPersonnel.getPersonnel_bank_title());
				cardMap.put("receivables_bank_branch", pmPersonnel.getPersonnel_bankName());
				cardMap.put("receivables_bank_number", addSpaceForCardNo(pmPersonnel.getPersonnel_bankCardCode()));

				cardMap.put("receivables_bank_pro", pmPersonnel.getBank_province_code());
				cardMap.put("receivables_bank_city", pmPersonnel.getBank_city_code());
				cardMap.put("receivables_bank_pro_name", pmPersonnel.getBank_province_str());
				cardMap.put("receivables_bank_city_name", pmPersonnel.getBank_city_str());
				cardMap.put("bank_num", pmPersonnel.getBank_num());

				collection_information_list.add(cardMap);
				ret_data.put("card_default", 1);
            	ret_data.put("related_bill_id", null);
            	ret_data.put("related_bill_code", "");
            	ret_data.put("related_bill_type", "");
            	ret_data.put("goods_price", "");
            	ret_data.put("related_bill_detail", "");	
            	
            	ret_data.put("confirm_date", "");
            	ret_data.put("confirm_amount", "");
            	
            	ret_data.put("pictureList", pictureList);

				ret_data.put("img_List", new ArrayList<Map<String, Object>>());

    		}
    		//ret_data.put("card_default"//如果选了其他收款卡则需要再给个默认收款卡
			if ("2".equals(ret_data.get("card_default").toString())) 
    		{
				Map<String, Object> cardMap = new HashMap<>();
				cardMap.put("receivables_name", pmPersonnel.getPersonnel_name());
				cardMap.put("receivables_bank", pmPersonnel.getPersonnel_bank_title());
				cardMap.put("receivables_bank_branch", pmPersonnel.getPersonnel_bankName());
				cardMap.put("receivables_bank_number", addSpaceForCardNo(pmPersonnel.getPersonnel_bankCardCode()));

				cardMap.put("receivables_bank_pro", pmPersonnel.getBank_province_code());
				cardMap.put("receivables_bank_city", pmPersonnel.getBank_city_code());
				cardMap.put("receivables_bank_pro_name", pmPersonnel.getBank_province_str());
				cardMap.put("receivables_bank_city_name", pmPersonnel.getBank_city_str());
				cardMap.put("bank_num", pmPersonnel.getBank_num());

				collection_information_list.add(0, cardMap);
    		}
			ret_data.put("collection_information_list", collection_information_list);

    		resMap.put("ret_data", ret_data);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", e.getMessage());
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * 
      * @Title: addSpaceForCardNo
      * @Description: 将卡号处理为4位一分隔
      * @param @param card_no
      * @param @return
      * @return String
      * @author: wangyihan
      * @time: 2020年10月26日 上午11:36:21
      * history:
      * 1、2020年10月26日 上午11:36:21 wangyihan 创建方法
      *
     */
    public static String addSpaceForCardNo(String card_no) 
    {
    	// 判断
    	if(StringUtils.isEmpty(card_no)) 
    	{
    		return "";
    	}
    	String card_no_new = "";
    	// 循环
    	for(int i = 0; i < card_no.toCharArray().length; i++) 
    	{
    		// 判断
    		if(i != 0 && (i + 1) % 4 == 0 && ((i + 1) != card_no.toCharArray().length)) 
    		{
    			card_no_new += card_no.toCharArray()[i] + " ";
    		} 
    		else 
    		{
    			card_no_new += card_no.toCharArray()[i];
    		}
    	}
    	return card_no_new;
    }
    
    /**
     * @Title: saveLoanInfo
     * @Description: MOA_OUT_004  借款单提交
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    @Transactional
    public Map<String, Object> saveLoanInfo(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
    		FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		FolFinaBillSubsidiaryDao folFinaBillSubsidiaryDao = (FolFinaBillSubsidiaryDao) FOLApplication.getBean("folFinaBillSubsidiaryDao");
    		PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
    		FolFinaLoanRelatedBillDao folFinaLoanRelatedBillDao = (FolFinaLoanRelatedBillDao) FOLApplication.getBean("folFinaLoanRelatedBillDao");
    		FolFileInfoDao folFileInfoDao = (FolFileInfoDao) FOLApplication.getBean("folFileInfoDao");
    		FolApplyBillRelationServiceImpl folApplyBillRelationServiceImpl = (FolApplyBillRelationServiceImpl) FOLApplication.getBean("folapplybillrelationService");
    		IFolFinaBillService folFinaBillService = (IFolFinaBillService) FOLApplication.getBean("folfinabillService");
    		SendWechatEmailMsgService sendWechatEmailMsgService = (SendWechatEmailMsgService) FOLApplication.getBean("sendWechatEmailMsgService");
    		FolApplyBillRelationDao folApplyBillRelationDao = (FolApplyBillRelationDao) FOLApplication.getBean("folApplyBillRelationDao");
    		
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		Map<String, Object> ret_data = new HashMap<String, Object>();
    		
    		// 提交类别标识 Initial_sort_id 1：提交 2：暂存
    		String Initial_sort_id = paramMap.get("Initial_sort_id").toString();
    		
    		PmPersonnel pmPersonnel = pmPersonnelDao.findPersonnelById(paramMap.get("user_id").toString());
    		
    		java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());
            
    		FolFinaBill bean1 = new FolFinaBill();
    		// 提交
    		if(Initial_sort_id.equals("1"))
    		{
    			bean1.setBill_state(2);
    		}
    		// 暂存
    		else if(Initial_sort_id.equals("2"))
    		{
    			bean1.setBill_state(1);
    		}
    		// 补充
    		else if(Initial_sort_id.equals("3"))
    		{
    			
    		}
    		bean1.setApply_user_id(pmPersonnel.getPersonnel_id());
            bean1.setApply_user_name(pmPersonnel.getPersonnel_name());
            bean1.setApply_user_shrotcode(pmPersonnel.getPersonnel_shortCode());
            bean1.setApply_user_postname(pmPersonnel.getPersonnel_postName());
            bean1.setApply_user_postid(pmPersonnel.getPersonnel_postId());
            bean1.setApply_user_deptid(pmPersonnel.getPersonnel_deptId());
            bean1.setApply_user_deptname(pmPersonnel.getPersonnel_deptName());
            bean1.setApply_user_pdeptid(pmPersonnel.getDept_pid());
            bean1.setApply_user_pdeptname(pmPersonnel.getDept_pname());
            bean1.setBill_type(1);
            bean1.setLast_update_timestamp(now_timestamp);
            bean1.setLast_update_user_id(pmPersonnel.getPersonnel_id());
            // 判断
            if(paramMap.get("fol_fina_bill_id") == null)
            {
            	bean1.setBill_code(CodeNoUtil.getLoanCreCode());
                bean1.setApply_date(new java.sql.Date(now_timestamp.getTime()));
                // 审批当前级别
                bean1.setCurrent_level(1);
                // 是否可以撤销 1可以 0不可以
                bean1.setIs_revoke(1);
                bean1.setCreate_timestamp(now_timestamp);
                bean1.setCreate_user_id(pmPersonnel.getPersonnel_id());
                bean1.setCreate_user_name(pmPersonnel.getPersonnel_name());
                bean1.setCreate_user_shortcode(pmPersonnel.getPersonnel_shortCode());
                bean1.setEnable_flag(1);
            	folFinaBillDao.save(bean1);
            }
            else
            {
            	bean1.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            	folFinaBillDao.update(bean1);
            	
            	bean1 = folFinaBillDao.get(bean1.getFol_fina_bill_id());
            	
            	// 删除附件
                Map<String, Object> paramMap_file = new HashMap<String, Object>();
                paramMap_file.put("fol_id", bean1.getFol_fina_bill_id());
                paramMap_file.put("attachment_module", FOLMsgInfo.FILE_CODE_DJSQ);
    			folFileInfoDao.deleteFilesForDJSQ(paramMap_file);
    			
    			 // 删除之前的审批节点
    			 Map<String, Object> paramMap_folApplyBillRelation = new HashMap<String, Object>();
    			 paramMap_folApplyBillRelation.put("fol_fina_bill_id", bean1.getFol_fina_bill_id());
    			 folApplyBillRelationDao.deleteFolApplyBillRelationByBillId(paramMap_folApplyBillRelation);
            }
            
            FolFinaBillSubsidiary bean2 = new FolFinaBillSubsidiary();
            bean2.setBill_cause(paramMap.get("bill_cause") != null ? paramMap.get("bill_cause").toString() : "");
            bean2.setLoan_amount(paramMap.get("loan_amount") != null ? new BigDecimal(paramMap.get("loan_amount").toString()) : null);
            
            String card_default = paramMap.get("card_default") != null ? paramMap.get("card_default").toString() : "1";
            bean2.setCard_default(Integer.parseInt(card_default));
            // 判断
			if (card_default.equals("2"))
            {
        		bean2.setReceivables_name(paramMap.get("receivables_name") != null ? paramMap.get("receivables_name").toString() : "");
        		bean2.setReceivables_bank(paramMap.get("receivables_bank") != null ? paramMap.get("receivables_bank").toString() : "");
        		bean2.setReceivables_bank_branch(paramMap.get("receivables_bank_branch") != null ? paramMap.get("receivables_bank_branch").toString() : "");
        		bean2.setReceivables_bank_number(paramMap.get("receivables_bank_number") != null ? paramMap.get("receivables_bank_number").toString() : "");
        		bean2.setReceivables_bank_pro(
						(paramMap.get("receivables_bank_pro") != null
								&& !paramMap.get("receivables_bank_pro").toString().equals("")) ?
        				paramMap.get("receivables_bank_pro").toString() : null
        		);
        		bean2.setReceivables_bank_city(
						(paramMap.get("receivables_bank_city") != null
								&& !paramMap.get("receivables_bank_city").toString().equals(""))
										?
        				paramMap.get("receivables_bank_city").toString() : null
        		);
				/*
				 * bean2.setReceivables_bank_pro( (paramMap.get("receivables_bank_pro") != null
				 * && !paramMap.get("receivables_bank_pro").toString().equals("")) ?
				 * paramMap.get("receivables_bank_pro").toString() : null );
				 * bean2.setReceivables_bank_city( (paramMap.get("receivables_bank_city") !=
				 * null && !paramMap.get("receivables_bank_city").toString().equals("")) ?
				 * paramMap.get("receivables_bank_city").toString() : null );
				 */
        		bean2.setBank_num(paramMap.get("bank_num") != null ? paramMap.get("bank_num").toString() : "");
            }
            else
            {
            	bean2.setReceivables_name(pmPersonnel.getPersonnel_name());
        		bean2.setReceivables_bank(pmPersonnel.getPersonnel_bank_title());
        		bean2.setReceivables_bank_branch(pmPersonnel.getPersonnel_bankName());
            	bean2.setReceivables_bank_number(pmPersonnel.getPersonnel_bankCardCode());
				bean2.setReceivables_bank_pro(pmPersonnel.getBank_province_code());
				bean2.setReceivables_bank_city(pmPersonnel.getBank_city_code());
            	bean2.setBank_num(pmPersonnel.getBank_num());
            }
            
            // 判断
            if(paramMap.get("img_List") != null)
            {
            	List<FolFileInfo> file_list = JSON
                        .parseObject(paramMap.get("img_List").toString(), new TypeReference<List<FolFileInfo>>()
                        {
                        });
                // 循环
                for (FolFileInfo bean_file : file_list)
                {
                	bean_file.setAttachment_new_name(bean_file.getAttachment_address().substring(bean_file.getAttachment_address().lastIndexOf("\\") + 1));
                	bean_file.setAttachment_type(bean_file.getAttachment_address().substring(bean_file.getAttachment_address().lastIndexOf(".")));
                    bean_file.setAttachment_module(FOLMsgInfo.FILE_CODE_DJSQ);
                    bean_file.setData_type_name(FOLMsgInfo.FILE_CODE_DJSQ_T);
                    bean_file.setData_detail_name(FOLMsgInfo.FILE_CODE_DJSQ_D);
                    bean_file.setFol_id(bean1.getFol_fina_bill_id());
                    bean_file.setFol_other_id(bean2.getFol_fina_bill_subsidiary_id());
                    bean_file.setEnable_flag(1);
                    folFileInfoDao.save(bean_file);
                }
            }
            
            // 判断
            if(paramMap.get("fol_fina_bill_subsidiary_id") == null)
            {
                bean2.setTotal_amount(bean2.getLoan_amount());
                bean2.setColl_pay_amount(bean2.getLoan_amount());
                // 判断
                if(paramMap.get("loan_type") != null && !paramMap.get("loan_type").toString().equals(""))
                {
                	bean2.setLoan_type(1);
                }
            	bean2.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
                bean2.setEnable_flag(1);
            	folFinaBillSubsidiaryDao.save(bean2);
            }
            else
            {
            	bean2.setFol_fina_bill_subsidiary_id(Integer.parseInt(paramMap.get("fol_fina_bill_subsidiary_id").toString()));
            	folFinaBillSubsidiaryDao.update(bean2);
            }
            
            FolFinaLoanRelatedBill bean = new FolFinaLoanRelatedBill();
            bean.setRelated_bill_code(paramMap.get("related_bill_code") != null ? paramMap.get("related_bill_code").toString() : "");
            bean.setRelated_bill_id(paramMap.get("related_bill_id") != null ? Integer.parseInt(paramMap.get("related_bill_id").toString()) : null);
            bean.setRelated_bill_tpye(paramMap.get("related_bill_type") != null ? paramMap.get("related_bill_type").toString() : "");
            bean.setGoods_price(paramMap.get("goods_price") != null ? paramMap.get("goods_price").toString() : "");
            bean.setRelated_bill_detail(paramMap.get("related_bill_detail") != null ? paramMap.get("related_bill_detail").toString() : "");
            // 判断
            if(StringUtils.isNotBlank(bean.getRelated_bill_code()) ||
            		bean.getRelated_bill_id() != null ||
            		StringUtils.isNotBlank(bean.getRelated_bill_tpye()) ||
            		StringUtils.isNotBlank(bean.getGoods_price()) ||
            		StringUtils.isNotBlank(bean.getRelated_bill_detail()))
            {
            	// 删除之前关联的物品申请单
            	List<Map<String, Object>> relatedList = folFinaLoanRelatedBillDao.search(paramMap);
            	// 判断
            	if(relatedList != null && relatedList.size() > 0)
            	{
            		FolFinaLoanRelatedBill bean_old = new FolFinaLoanRelatedBill();
            		bean_old.setFol_fina_loan_related_bill_id(Integer.parseInt(relatedList.get(0).get("fol_fina_loan_related_bill_id").toString()));
            		bean_old.setEnable_flag(0);
            		folFinaLoanRelatedBillDao.update(bean_old);
            		
            		paramMap.put("fol_other_id", bean.getFol_fina_loan_related_bill_id());
                    folFileInfoDao.deleteFilesForWPSQD(paramMap);
            	}
            	
        		bean.setRelated_bill_id(Integer.parseInt(paramMap.get("related_bill_id").toString()));
        		bean.setFol_fina_bill_id(bean1.getFol_fina_bill_id());
        		bean.setFol_fina_bill_subsidiary_id(bean2.getFol_fina_bill_subsidiary_id());
        		bean.setCreate_timestamp(now_timestamp);
        		bean.setCreate_user_id(pmPersonnel.getPersonnel_id());
        		bean.setCreate_user_name(pmPersonnel.getPersonnel_name());
        		bean.setCreate_user_shortcode(pmPersonnel.getPersonnel_shortCode());
        		bean.setEnable_flag(1);
        		folFinaLoanRelatedBillDao.save(bean);
        		
        		// 判断
        		if(paramMap.get("img_path") != null)
        		{
        			List<FolFileInfo> file_list = JSON
        					.parseObject(paramMap.get("img_path").toString(), new TypeReference<List<FolFileInfo>>()
        					{
        					});
        			// 循环
        			for (FolFileInfo bean_file : file_list)
        			{
						bean_file.setFol_file_info_id(null);
        				bean_file.setAttachment_module(FOLMsgInfo.FILE_CODE_WPSQD);
        				bean_file.setFol_id(bean.getFol_fina_bill_id());
        				bean_file.setFol_other_id(bean.getFol_fina_loan_related_bill_id());
        				bean_file.setEnable_flag(1);
        				folFileInfoDao.save(bean_file);
        			}
        		}
            }
            else
            {
            	// 删除之前关联的物品申请单
            	paramMap.put("enable_flag", "1");
            	List<Map<String, Object>> relatedList = folFinaLoanRelatedBillDao.search(paramMap);
            	// 判断
            	if(relatedList != null && relatedList.size() > 0)
            	{
            		FolFinaLoanRelatedBill bean_old = new FolFinaLoanRelatedBill();
            		bean_old.setFol_fina_loan_related_bill_id(Integer.parseInt(relatedList.get(0).get("fol_fina_loan_related_bill_id").toString()));
            		bean_old.setEnable_flag(0);
            		folFinaLoanRelatedBillDao.update(bean_old);
            		
            		paramMap.put("fol_other_id", bean.getFol_fina_loan_related_bill_id());
                    folFileInfoDao.deleteFilesForWPSQD(paramMap);
            	}
            }

            // 调用流程(1草稿 2 审核中 3 待签收4 已完成 0已作废)
            if (bean1.getBill_state() != null && bean1.getBill_state().intValue() == 2)
            {
            	// 判断是否为补充：不保存流程
            	if(!paramMap.get("Initial_sort_id").toString().equals("3"))
            	{
            		/**
            		 * @param id  申请人
            		 * @param bill_id 单据id
            		 * @param apply_type 审批类型
            		 * @param var 条件参数
            		 */
            		List<FolApplyBillRelation> folApplyList = folApplyBillRelationServiceImpl
            				.getFOLFlowRelationByUserId(bean1.getApply_user_id().toString(), bean1.getFol_fina_bill_id(),
            						bean1.getBill_type(), bean2.getLoan_amount().toString());
            		//判断不为空
            		if (folApplyList != null && folApplyList.size() > 0)
            		{
            			folApplyBillRelationServiceImpl.saveBatch(folApplyList, pmPersonnel);
            		}
            		
            		FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
            		// 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
            		approvalBean.setApproval_result("4");
            		// 审批意见
            		approvalBean.setApproval_advice("提交成功。");
            		// 流程节点code
            		approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_TJ);
            		// 流程节点名称
            		approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_TJ);
            		approvalBean.setFol_id(bean1.getFol_fina_bill_id());
            		// 流程生成
            		folFinaBillService.generateApprovalBean(approvalBean, pmPersonnel);
            	}
            }
            
            try
            {
                // 发送微信消息
                Map<String, Object> param = new HashMap<>();
                param.put("msg_code", "10001");
                param.put("fol_fina_bill_id", bean1.getFol_fina_bill_id());
                param.put("bill_code", bean1.getBill_code());
                param.put("user_name_shortcode", bean1.getApply_user_name() + " " + bean1.getApply_user_shrotcode());
                param.put("keyword1", FOLMsgInfo.APPROVAL_TYPE_DSP);
                sendWechatEmailMsgService.sendWechat(param);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

    		resMap.put("ret_data", ret_data);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e) 
    	{
            // 回滚事物
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * @Title: getBillList
     * @Description: MOA_OUT_009  财务单据列表
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    public Map<String, Object> getBillList(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
    		FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		Map<String, Object> paramMap = queryInfo.getParamMap();
            
    		DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
    		
    		paramMap.put("bill_type", paramMap.get("bill_type") != null && !paramMap.get("bill_type").equals("") ? "(" + paramMap.get("bill_type") + ")" : null);
    		paramMap.put("bill_state", paramMap.get("bill_state") != null && !paramMap.get("bill_state").equals("") ? "(" + paramMap.get("bill_state") + ")" : null);
            paramMap.put("sortname", "t1.fol_fina_bill_id");
            paramMap.put("sortorder", "desc");
            List<Map<String, Object>> list = folFinaBillDao.getBillList(paramMap);
            
            // 循环
            for(Map<String, Object> tmpMap : list)
            {
            	StringBuffer oper_flag = new StringBuffer();
            	// 金额字段格式化
            	tmpMap.put("total_amount", tmpMap.get("total_amount") != null ? decimalFormat.format(new BigDecimal(tmpMap.get("total_amount").toString())) : "-/-");
            	// 可操作项 oper_flag：1撤回；2补充；3编辑；4作废；5流程
            	// 草稿
            	if(tmpMap.get("bill_state").toString().equals("1"))
            	{
            		tmpMap.put("oper_flag", "3,4");
            	}
            	// 审核中
            	else if(tmpMap.get("bill_state").toString().equals("2"))
            	{
            		// 判断是否可撤回
            		if((tmpMap.get("is_revoke").toString().equals("1")))
            		{
            			oper_flag.append("1,");
            		}
            		// 判断是否可补充 
            		if(tmpMap.get("is_show_bc_flag").toString().equals("1"))
            		{
            			oper_flag.append("2,");
            		}
            		oper_flag.append("5");
            		tmpMap.put("oper_flag", oper_flag.toString());
            	}
            	// 待确认
            	else if(tmpMap.get("bill_state").toString().equals("3"))
            	{
            		// 判断是否可补充 
            		if(tmpMap.get("is_show_bc_flag").toString().equals("1"))
            		{
            			oper_flag.append("2,");
            		}
            		oper_flag.append("5");
            		tmpMap.put("oper_flag", oper_flag.toString());
            	}
            	// 已完成
            	else if(tmpMap.get("bill_state").toString().equals("4"))
            	{
            		tmpMap.put("oper_flag", "5");
            	}
            	// 已作废
            	else if(tmpMap.get("bill_state").toString().equals("0"))
            	{
            		tmpMap.put("oper_flag", "5");
            	}
            	tmpMap.remove("is_revoke");
            	tmpMap.remove("is_show_bc_flag");
            }
            
    		resMap.put("ret_data", list);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * @Title: saveBillRevoke
     * @Description: MOA_OUT_010  财务单据提交（撤回）
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    @Transactional
    public Map<String, Object> saveBillRevoke(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
    		FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		FolFinaBillSubsidiaryDao folFinaBillSubsidiaryDao = (FolFinaBillSubsidiaryDao) FOLApplication.getBean("folFinaBillSubsidiaryDao");
    		PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
    		IFolFinaBillService folFinaBillService = (IFolFinaBillService) FOLApplication.getBean("folfinabillService");
    		SendWechatEmailMsgService sendWechatEmailMsgService = (SendWechatEmailMsgService) FOLApplication.getBean("sendWechatEmailMsgService");
    		
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		Map<String, Object> ret_data = new HashMap<String, Object>();
    		
            java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());

            Integer user_id = Integer.parseInt(paramMap.get("user_id").toString());
            FolFinaBill bean = new FolFinaBill();
            bean.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            bean.setLast_update_timestamp(now_timestamp);
            bean.setLast_update_user_id(user_id);
            // 草稿
            bean.setBill_state(1);
            folFinaBillDao.update(bean);
            // 查询当前审批相关状态信息
            Map<String, Object> applyInfoMap = folFinaBillDao.getBillInfo(paramMap);
            // 单据类型 1借款 2费用报销 3出差报销
            // 报销方式 1报销2冲账
            if ("2".equals(applyInfoMap.get("bill_type").toString()) && applyInfoMap.get("reimburse_type") != null
					&& "2".equals(applyInfoMap.get("reimburse_type").toString()))
            {
               	/*
				 * // 更新关联借款单的余额字段 Map<String, Object> pMap = new HashMap<>();
				 * pMap.put("fol_fina_bill_subsidiary_id",
				 * applyInfoMap.get("fol_fina_bill_subsidiary_id_relation"));
				 * folFinaBillSubsidiaryDao.updateSubsidiaryBalanceAmount(pMap);
				 */
				// 不为空
				if (applyInfoMap.get("fol_fina_bill_subsidiary_id_loans") != null) 
				{
					// 循环
					for (String id_loan : applyInfoMap.get("fol_fina_bill_subsidiary_id_loans").toString().split(",")) 
					{
						// 更新关联借款单的余额字段
						Map<String, Object> pMap = new HashMap<>();
						pMap.put("fol_fina_bill_subsidiary_id", id_loan);
						folFinaBillSubsidiaryDao.updateSubsidiaryBalanceAmount(pMap);
					}
				}
            }

            FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
            // 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
            approvalBean.setApproval_result("0");
            // 审批意见
            approvalBean.setApproval_advice("单据撤回。");
            // 流程节点code
            approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_CH);
            // 流程节点名称
            approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_CH);
            approvalBean.setFol_id(bean.getFol_fina_bill_id());
            // 流程生成
            folFinaBillService.generateApprovalBean(approvalBean, pmPersonnelDao.findPersonnelById(user_id.toString()));
    		
            try
            {
                bean = folFinaBillDao.get(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
                Map<String, Object> param = new HashMap<>();
                param.put("msg_code", "10006");
                param.put("fol_fina_bill_id", bean.getFol_fina_bill_id());
                param.put("bill_code", bean.getBill_code());
                param.put("user_name_shortcode", bean.getApply_user_name() + " " + bean.getApply_user_shrotcode());
                param.put("keyword1", FOLMsgInfo.APPROVAL_TYPE_TZXX);
                sendWechatEmailMsgService.sendWechat(param);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            
    		resMap.put("ret_data", ret_data);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e)
    	{
    		// 回滚事物
    		TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * @Title: saveBillVoid
     * @Description: MOA_OUT_011  财务单据提交（作废）
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    @Transactional
    public Map<String, Object> saveBillVoid(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try
    	{
    		FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		PmPersonnelDao pmPersonnelDao = (PmPersonnelDao) FOLApplication.getBean("pmPersonnelDao");
    		IFolFinaBillService folFinaBillService = (IFolFinaBillService) FOLApplication.getBean("folfinabillService");
    		
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		Map<String, Object> ret_data = new HashMap<String, Object>();
    		
    		java.sql.Timestamp now_timestamp = new java.sql.Timestamp(System.currentTimeMillis());

    		Integer user_id = Integer.parseInt(paramMap.get("user_id").toString());
            FolFinaBill bean = new FolFinaBill();
            bean.setFol_fina_bill_id(Integer.parseInt(paramMap.get("fol_fina_bill_id").toString()));
            bean.setLast_update_timestamp(now_timestamp);
            bean.setLast_update_user_id(user_id);
            // 已作废
            bean.setBill_state(0);
            folFinaBillDao.update(bean);

            // 调用流程(1草稿 2 审核中 3 待签收4 已完成 0已作废)
            FolCreApprovalInfo approvalBean = new FolCreApprovalInfo();
            // 流程审批结果 0 单据撤销 1审批通过 2审批拒件 3 财务确认 4提交单据
            approvalBean.setApproval_result("2");
            // 审批意见
            approvalBean.setApproval_advice("单据作废。");
            // 流程节点code
            approvalBean.setApproval_task_code(FOLMsgInfo.APPROVAL_TASK_CODE_ZF);
            // 流程节点名称
            approvalBean.setApproval_task_name(FOLMsgInfo.APPROVAL_TASK_NAME_ZF);
            approvalBean.setFol_id(bean.getFol_fina_bill_id());
            // 流程生成
            folFinaBillService.generateApprovalBean(approvalBean, pmPersonnelDao.findPersonnelById(user_id.toString()));
    		
    		resMap.put("ret_data", ret_data);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e)
    	{
    		// 回滚事物
    		TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * @Title: getFlowList
     * @Description: MOA_OUT_020  流程历程
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    public Map<String, Object> getFlowList(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try
    	{
    		FolApplyBillRelationDao folApplyBillRelationDao = (FolApplyBillRelationDao) FOLApplication.getBean("folApplyBillRelationDao");
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		
    		List<Map<String, Object>> flowList = folApplyBillRelationDao.searchFolApplyBillRelationList(paramMap);
    		List<Map<String, Object>> new_flowList = new ArrayList<Map<String, Object>>();
    		Map<String, Object> new_flow_map = new HashMap<String, Object>();
    		List<Map<String, Object>> retflowList = new ArrayList<>();
    		//判断不为空
    		if(flowList != null && flowList.size() > 0)
    		{
    			Map<String, Object> flowMap = new HashMap<>();
    			// 循环
        		for(Map<String, Object> tmpMap : flowList)
        		{
        			new_flow_map = new HashMap<String, Object>();
        			new_flow_map.put("level_index", tmpMap.get("level_index"));
        			new_flow_map.put("level_flag", tmpMap.get("level_flag"));
        			new_flow_map.put("approval_user_name", tmpMap.get("approval_user_name").toString() + " " + tmpMap.get("approval_user_shortcode").toString());
        			new_flow_map.put("approval_user_deptName", tmpMap.get("approval_user_deptName"));
        			new_flow_map.put("approval_user_postname", tmpMap.get("approval_user_postname"));
    				new_flow_map.put("approval_state", tmpMap.get("approval_state"));
        			new_flow_map.put("approval_advice", tmpMap.get("approval_advice"));
        			new_flow_map.put("approval_timestamp", tmpMap.get("approval_timestamp"));
        			new_flowList.add(new_flow_map);
        		}
    			
    			// 循环
    			for (Map<String, Object> map : new_flowList)
    			{
    				// 判断是否包含这个审批级别
    				if (flowMap.containsKey(map.get("level_index").toString()))
    				{
    					List<Map<String, Object>> list = (List) flowMap.get(map.get("level_index").toString());
    					list.add(map);
    				}
    				else 
    				{
    					List<Map<String, Object>> list = new ArrayList<>();
    					list.add(map);
    					flowMap.put(map.get("level_index").toString(), list);
    				}
    			}
    			// 循环 处理数据格式
    			for(String level_index : flowMap.keySet())
    			{
    				Map<String, Object> map = new HashMap<>();
    				map.put("level_flag", ((List<Map<String, Object>>) flowMap.get(level_index)).get(0).get("level_flag"));
    				map.put("level_list", flowMap.get(level_index));
    				retflowList.add(map);
    			}
    		}
    		//判断是否存在流程历程
			if (retflowList != null && retflowList.size() > 0)
    		{
    			resMap.put("ret_data", retflowList);
        		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
        		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    		}
    		else 
    		{
    			resMap.put("ret_data", retflowList);
				resMap.put("ret_msg", "未提交单据，无审批信息");
        		resMap.put("ret_code", ResultHelper.RET_SUCCESS);	
    		}
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * @Title: getRelatedBillList
     * @Description: MOA_OUT_023  关联物品申请单
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: wangyihan
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 wangyihan 创建方法
    */
    public Map<String, Object> getRelatedBillList(FolRequestForMobileSearchBeanVO queryInfo) 
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		
            // 调取IOA接口
            RestTemplate restTemplate = new RestTemplate();
            MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
            // 接口编号
            form.add("interface_num", "IOA_OUT_order");
            // 系统编号
            form.add("sys_num", "FOL");
            form.add("related_bill_code", paramMap.get("bill_code") != null ? paramMap.get("bill_code").toString() : "");
            form.add("apply_date_begin", paramMap.get("apply_date_begin") != null ? paramMap.get("apply_date_begin").toString() : "");
            form.add("apply_date_end", paramMap.get("apply_date_end") != null ? paramMap.get("apply_date_end").toString() : "");
            form.add("personnel_id", paramMap.get("user_id").toString());
            form.add("page", paramMap.get("page").toString() + "");
            form.add("pagesize", paramMap.get("pagesize").toString() + "");

            // 调用IOA接口
            Map<String, Object> map = restTemplate.postForObject(GlobalVal.getProperty("nozzleUrl"), form, Map.class);
            Map<String, Object> res_map = (Map<String, Object>) map.get("ret_data");
            List<Map<String, Object>> list = (List<Map<String, Object>>) res_map.get("rows");
    		// 循环
            for(Map<String, Object> tmpMap : list)
    		{
    			tmpMap.remove("apply_date");
    			tmpMap.put("related_bill_type", tmpMap.get("related_bill_tpye"));
    			tmpMap.remove("related_bill_tpye");
    		}
    		resMap.put("ret_data", list);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.MSG_RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
    
    /**
     * @Title: getApplyList
     * @Description: 2.7.7MOA_OUT_007 财务审批列表
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: baisong
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 baisong 创建方法
    */
	public Map<String, Object> getApplyList(FolRequestForMobileSearchBeanVO queryInfo)
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
			DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
			FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		Map<String, Object> paramMap = queryInfo.getParamMap();

			paramMap.put("sortname", "b.fol_fina_bill_id");
			paramMap.put("sortorder", "asc");
			List<Map<String, Object>> list = folFinaBillDao.searchTodoList_M(paramMap);
			// 循环
			for (Map<String, Object> map : list)
			{
				// 不为空
				if (map.get("total_amount") != null && !"".equals(map.get("total_amount").toString())) 
				{
					map.put("total_amount", decimalFormat.format(new BigDecimal(map.get("total_amount").toString())));
				}
			}
    		resMap.put("ret_data", list);
    		resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
	 /**
     * @Title: saveApplyInfo
     * @Description: 2.7.8MOA_OUT_008 财务审批提交
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: baisong
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 baisong 创建方法
    */
	public Map<String, Object> saveApplyInfo(FolRequestForMobileSearchBeanVO queryInfo)
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
			// DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
			FolFinaBillServiceImpl folfinabillService = (FolFinaBillServiceImpl) FOLApplication
					.getBean("folfinabillService");
    		Map<String, Object> paramMap = queryInfo.getParamMap();
			FolFinaBillSearchBeanVO folFinaBillSearchBeanVO = new FolFinaBillSearchBeanVO();
			folFinaBillSearchBeanVO.setFol_apply_bill_relation_id(Integer.valueOf(paramMap.get("fol_apply_bill_relation_id").toString()));
			folFinaBillSearchBeanVO.setUser_id(Integer.valueOf(paramMap.get("user_id").toString()));
			folFinaBillSearchBeanVO.setIs_mobile(1);
			folFinaBillSearchBeanVO.setApproval_advice(paramMap.get("approval_advice")==null?"":paramMap.get("approval_advice").toString());
			folFinaBillSearchBeanVO.setApproval_state(Integer.valueOf(paramMap.get("approval_result").toString()));
			Map<String, Object> result = folfinabillService.saveBatchApplyInfo(folFinaBillSearchBeanVO);
			// 判断是否成功
			if ("success".equals(result.get("result").toString())) 
			{
				resMap.put("ret_data", result);
				resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
				resMap.put("ret_code", ResultHelper.RET_SUCCESS);
			}
			else
			{
				resMap.put("ret_data", result);
				resMap.put("ret_msg", ResultHelper.RET_ERROR);
				resMap.put("ret_code", ResultHelper.RET_ERROR);
			}

    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
	 /**
     * @Title: getPayConfirmList
     * @Description: 2.7.12MOA_OUT_012 收付款列表
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: baisong
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 baisong 创建方法
    */
	public Map<String, Object> getPayConfirmList(FolRequestForMobileSearchBeanVO queryInfo)
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
			DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
			FolFinaBillDao folFinaBillDao = (FolFinaBillDao) FOLApplication.getBean("folFinaBillDao");
    		Map<String, Object> paramMap = queryInfo.getParamMap();

            // 判断
			if (paramMap.get("apply_user_name") != null && !"".equals(paramMap.get("apply_user_name").toString()))
            {
				paramMap.put("apply_user_name_or_shortcode", paramMap.get("apply_user_name"));
				paramMap.put("apply_user_name", paramMap.get("apply_user_name"));
				paramMap.put("apply_user_shrotcode", paramMap.get("apply_user_name"));
            }

			paramMap.put("sortname", "t1.fol_fina_bill_id");
			paramMap.put("sortorder", "asc");
			List<Map<String, Object>> list = folFinaBillDao.getPayConfirmList(paramMap);
			// 循环
			for (Map<String, Object> map : list)
			{
				// 不为空
				if (map.get("total_amount") != null && !"".equals(map.get("total_amount").toString())) 
				{
					map.put("total_amount", decimalFormat.format(new BigDecimal(map.get("total_amount").toString())));
				}
				// `bill_type` int(11) DEFAULT NULL COMMENT '单据类型 1借款 2费用报销 3出差报销',
				String bill_type = map.get("bill_type") != null ? map.get("bill_type").toString() : "";
				// `reimburse_type` int(11) DEFAULT NULL COMMENT '报销方式 1报销2冲账',
				String reimburse_type = map.get("reimburse_type") != null ? map.get("reimburse_type").toString() : "";
				//  `charge_off_type` int(11) DEFAULT NULL COMMENT '冲账方式 1 补充打款  2 还借款 3 全额冲账 4累加冲账',
				String charge_off_type = map.get("charge_off_type") != null ? map.get("charge_off_type").toString() : "";
				// 1 付款 2 收款 3 冲账 4累加 5还款
				int confirm_type = 1;
				//费用报销单  冲账 还借款
				if ("2".equals(bill_type)&&"2".equals(reimburse_type)&&"2".equals(charge_off_type))
				{
					confirm_type=2;
				}
				else if("2".equals(bill_type)&&"2".equals(reimburse_type)&&"3".equals(charge_off_type))
				{
					confirm_type=3;
				}
				else if("2".equals(bill_type)&&"2".equals(reimburse_type)&&"4".equals(charge_off_type))
				{
					confirm_type=4;
				}
				//借款单
				else if ("1".equals(bill_type) && map.get("balance_amount") != null
						&& new BigDecimal(map.get("balance_amount").toString()).compareTo(BigDecimal.ZERO) > 0)
				{
					confirm_type = 5;
				}
				map.put("confirm_type", confirm_type);
			}
    		resMap.put("ret_data", list);
    		resMap.put("ret_msg", ResultHelper.RET_SUCCESS);
    		resMap.put("ret_code", ResultHelper.RET_SUCCESS);
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
    		resMap.put("ret_msg", ResultHelper.RET_ERROR);
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
	
	
	/**
     * @Title: savePayConfirm
     * @Description: 2.7.13MOA_OUT_013 收付款确认提交
     * @param FolRequestForMobileSearchBeanVO queryInfo
     * @return 
     * @author: baisong
     * @time:2020年10月9日 上午10:00:00
     * history:
     * 1、2020年10月9日 上午10:00:00 baisong 创建方法
    */
	public Map<String, Object> savePayConfirm(FolRequestForMobileSearchBeanVO queryInfo)
    {
    	Map<String, Object> resMap = new HashMap<String, Object>();
    	try 
    	{
			// DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
    		FolFinaCollectionPayConfirmServiceImpl folFinaCollectionPayConfirmService = (FolFinaCollectionPayConfirmServiceImpl) FOLApplication
					.getBean("folfinacollectionpayconfirmService");
    		Map<String, Object> paramMap = queryInfo.getParamMap();
    		FolFinaCollectionPayConfirmSearchBeanVO payConfirmSearchBeanVO = new FolFinaCollectionPayConfirmSearchBeanVO();
			payConfirmSearchBeanVO.setConfirm_type(Integer.valueOf(paramMap.get("confirm_type").toString()));
			payConfirmSearchBeanVO.setFol_fina_bill_id(Integer.valueOf(paramMap.get("fol_fina_bill_id").toString()));
    		payConfirmSearchBeanVO.setFol_fina_bill_subsidiary_id(Integer.valueOf(paramMap.get("fol_fina_bill_subsidiary_id").toString()));
    		//图片信息
    		if(paramMap.get("pictureList")!=null) 
    		{
    			payConfirmSearchBeanVO.setFile_json(paramMap.get("pictureList").toString());
    		}
			payConfirmSearchBeanVO.setConfirm_amount(new BigDecimal(paramMap.get("confirm_amount").toString()));
			payConfirmSearchBeanVO.setConfirm_date(paramMap.get("confirm_date").toString());
			payConfirmSearchBeanVO.setIs_mobile(1);
			payConfirmSearchBeanVO.setUser_id(Integer.valueOf(paramMap.get("user_id").toString()));
			Map<String, Object> result = folFinaCollectionPayConfirmService.saveCollectionPayConfirm(payConfirmSearchBeanVO);
			// 判断是否成功
			if ("success".equals(result.get("result").toString())) 
			{
				resMap.put("ret_data", result);
				resMap.put("ret_msg", "操作成功!");
				resMap.put("ret_code", ResultHelper.RET_SUCCESS);
			}
			else
			{
				resMap.put("ret_data", result);
				resMap.put("ret_msg", "操作失败，请联系客服!");
				resMap.put("ret_code", ResultHelper.RET_ERROR);
			}
    	} 
    	catch (Exception e) 
    	{
            e.printStackTrace();
    		resMap.put("ret_data", null);
			resMap.put("ret_msg", "操作失败，请联系客服!");
    		resMap.put("ret_code", ResultHelper.RET_ERROR);
		}
        return resMap;
    }
}
